
//preloading.....
load("library/common.js");

JEuler.system.loadJS("library/math.js");

(function() {

    //JEuler.system.loadJS("data/???.dat");
    JEuler.system.printCaption("092");
    JEuler.system.startTimerCount();
    
    function getNext(n) {
        var tmp = n, p, sum=0;
        while(tmp>0) {
            p = tmp%10;
            sum = sum + p*p;
            tmp = (tmp-p)/10;
        }
        return sum;
    };
    
    var LIMIT = 10000000;
    
    var count = 1, step, sum=0;
    for(var i=1; i<=LIMIT; i++) {
        step = i;
        while(step!=1 && step !=89) {
            step = getNext(step);
        }
        if(step==89) sum++;
    }


    JEuler.system.print("SUM=" + sum);
    JEuler.system.printTimerCount();
    
})();
